using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraSplashScreen;

namespace Comteck.Winforms.Utils {
  /// <summary>
  /// devexpress
  /// </summary>
  public partial class WinformHelper {

    /// <summary>
    /// 
    /// </summary>
    public const string WAIT_MESSAGE = "请等待";

    /// <summary>
    /// 
    /// </summary>
    public const string DEFAULT_TITLE = "提示";

    /// <summary>
    /// 
    /// </summary>
    public const string DEFAULT_CAPTION = "正在处理中…";

    /// <summary>
    /// 
    /// </summary>
    public static Size DEFAULT_SIZE = new Size(100, 50);

    #region LoadWaitScreen + LoadWaitForm

    /// <summary>
    /// 
    /// </summary>
    /// <param name="screen"></param>
    public static void ShowLoadScreen() {
      ShowLoadScreen(typeof(FrmLoadWaitScreen));
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="screen"></param>
    public static void ShowLoadScreen(Type splashFormType) {
      SplashScreenManager.ShowForm(splashFormType);
    }

    /// <summary>
    /// 提示信息
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="arg"></param>
    public static void SendLoadScreenCommand(LoadWaitScreenCommand cmd, object arg = null) {
      try {
        if (SplashScreenManager.Default == null) {
          return;
        }

        SplashScreenManager.Default.SendCommand(cmd, arg);
      } catch {
      }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="screen"></param>
    public static void CloseLoadScreen() {
      SplashScreenManager.CloseForm(false);
    }

    #endregion

    #region LoadWaitForm1

    ///// <summary>
    ///// 
    ///// </summary>
    ///// <param name="parentForm"></param>
    //public static void ShowLoadForm(Form parentForm, string desc = null) {
    //  ShowLoadForm(parentForm, typeof(FrmWaitForm), desc);
    //}

    ///// <summary>
    ///// 
    ///// </summary>
    ///// <param name="parentForm"></param>
    ///// <param name="formType"></param>
    //public static void ShowLoadForm(Form parentForm, Type formType, string desc = null) {
    //  SplashScreenManager.ShowForm(parentForm, formType, true, true, false);

    //  if (String.IsNullOrWhiteSpace(desc) == false) {
    //    SplashScreenManager.Default.SetWaitFormDescription(desc);
    //  }
    //}

    ///// <summary>
    ///// 提示信息
    ///// </summary>
    ///// <param name="cmd"></param>
    ///// <param name="arg"></param>
    //public static void SendLoadFormCommand(LoadWaitFormCommand cmd, object arg = null) {
    //  if (SplashScreenManager.Default == null) {
    //    return;
    //  }

    //  SplashScreenManager.Default.SendCommand(cmd, arg);
    //}

    ///// <summary>
    ///// 
    ///// </summary>
    ///// <param name="parentForm">父界面</param>
    ///// <param name="delay"></param>
    ///// <param name="desc"></param>
    //public static void CloseLoadForm(Form parentForm, int delay = 0,
    //  string title = null, string desc = null) {

    //  if (string.IsNullOrWhiteSpace(title)) {
    //    SendLoadFormCommand(LoadWaitFormCommand.ChangeTitle, WAIT_MESSAGE);
    //  } else {
    //    SendLoadFormCommand(LoadWaitFormCommand.ChangeTitle, title);
    //  }

    //  if (string.IsNullOrEmpty(desc) == false) {
    //    SendLoadFormCommand(LoadWaitFormCommand.ChangeDesc, desc);
    //  }

    //  SplashScreenManager.CloseForm(false, delay, parentForm);
    //}

    #endregion

    #region LoadWaitForm2

    /// <summary>
    /// 同步查询做相关提示
    /// </summary>
    /// <param name="caption"></param>
    /// <param name="title"></param>
    /// <param name="size"></param>
    /// <param name="parent"></param>
    /// <param name="action"></param>
    public static void ShowWaitFormSync(Form parent, Action action) {
      ShowWaitFormSync(DEFAULT_CAPTION, DEFAULT_TITLE, DEFAULT_SIZE, parent, action);
    }

    /// <summary>
    /// 同步查询做相关提示
    /// </summary>
    /// <param name="caption"></param>
    /// <param name="title"></param>
    /// <param name="size"></param>
    /// <param name="parent"></param>
    /// <param name="action"></param>
    public static void ShowWaitFormSync(string caption, string title, Size size, Form parent, Action action) {
      caption = caption ?? DEFAULT_CAPTION;
      title = title ?? DEFAULT_TITLE;

      using (var waitDialogForm = new WaitDialogForm(caption, title, size, parent)) {
        action();
      }
    }

    #endregion

  }
}
